package web.servlet.old;

/**
 * @Author:fhx
 * @Date:2024/4/19
 * @Project:BrandWork
 */
import com.alibaba.fastjson.JSON;

import java.io.IOException;
import java.util.List;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import pojo.Brand;
import service.BrandService;
import service.impl.BrandServiceImpl;
@WebServlet({"/SelectAllServlet"})
public class SelectAllServlet extends HttpServlet {
    private BrandService brandService = new BrandServiceImpl();

    public SelectAllServlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Brand> brands = this.brandService.selectAll();
        String jsonString = JSON.toJSONString(brands);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
